home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmigaPlus / Tools / Development / MCC_TheBar / Developer / C / Examples / demo7.c < prev    next >
Encoding:
C/C++ Source or Header  |  2004-01-31  |  9.6 KB  |  339 lines

  1.  
  2. #include <proto/exec.h>
  3. #include <proto/dos.h>
  4. #include <proto/muimaster.h>
  5. #include <clib/alib_protos.h>
  6. #include <mui/TheBar_mcc.h>
  7. #include <string.h>
  8. #include <stdio.h>
  9.  
  10. /***********************************************************************/
  11.  
  12. long __stack = 8192;
  13. struct Library *MUIMasterBase;
  14.  
  15. /***********************************************************************/
  16.  
  17. #ifndef MAKE_ID
  18. #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
  19. #endif
  20.  
  21. #define SAVEDS  __saveds
  22. #define ASM     __asm
  23. #define REG(x)  register __ ## x
  24. #define STDARGS __stdargs
  25.  
  26. #define mainGroupObject NewObject(mainGroupClass->mcc_Class,NULL
  27.  
  28. #define DD_FACT 5
  29.  
  30. /***********************************************************************/
  31.  
  32. ULONG STDARGS
  33. DoSuperNew(struct IClass *cl,Object *obj,ULONG tag1,...)
  34. {
  35.     return DoSuperMethod(cl,obj,OM_NEW,&tag1,NULL);
  36. }
  37.  
  38. /***********************************************************************/
  39.  
  40. struct data
  41. {
  42.     Object *bar;
  43.     Object *list;
  44.     ULONG  barPos;
  45. };
  46.  
  47. enum
  48. {
  49.     BARPOS_TOP = 1,
  50.     BARPOS_BOTTOM,
  51.     BARPOS_LEFT,
  52.     BARPOS_RIGHT,
  53. };
  54.  
  55. /***********************************************************************/
  56.  
  57. struct MUIS_TheBar_Button buttons[] =
  58. {
  59.     {7,  0, "_Face",  "Just a face."     },
  60.     {14, 1, "_Mouse", "Your mouse."      },
  61.     {17, 2, "_Tree",  "Mind takes place."},
  62.     {MUIV_TheBar_BarSpacer, -1},
  63.     {26, 3, "_Help",  "Read this!."      },
  64.     {34, 4, "_ARexx", "ARexx for ever!." },
  65.     {1,  5, "_Host",  "Your computer."   },
  66.     {MUIV_TheBar_End},
  67. };
  68.  
  69. #define TEXT "\
  70. This example shows how to move the bar around.\n\n\
  71. Of course, this is only a semplification of a real situation, where more than four positions are available and many objects are involved.\n\n\
  72. Programmers should always avoid to Init/Exit Change and to set Horiz on groups or whatever when not strictly needed!\
  73. "
  74.  
  75. ULONG
  76. mNew(struct IClass *cl,Object *obj,struct opSet *msg)
  77. {
  78.     Object *bar, *list;
  79.  
  80.     if (obj = (Object *)DoSuperNew(cl,obj,
  81.  
  82.             Child, bar = TheBarVirtObject,
  83.                 MUIA_Group_Horiz,            TRUE,
  84.                 MUIA_TheBar_Buttons,         buttons,
  85.                 MUIA_TheBar_PicsDrawer,      "PROGDIR:Pics",
  86.                 MUIA_TheBar_Strip,           "symbols",
  87.                 MUIA_TheBar_StripCols,       16,
  88.                 MUIA_TheBar_StripRows,       3,
  89.                 MUIA_TheBar_StripHorizSpace, 0,
  90.                 MUIA_TheBar_StripVertSpace,  0,
  91.                 MUIA_TheBar_Frame,           TRUE,
  92.                 MUIA_TheBar_DragBar,         TRUE,
  93.                 MUIA_TheBar_EnableKeys,      TRUE,
  94.             End,
  95.  
  96.             Child, list = ListviewObject,
  97.                 MUIA_Listview_List,  FloattextObject,
  98.                     TextFrame,
  99.                     MUIA_Background,     MUII_TextBack,
  100.                     MUIA_Floattext_Text, TEXT,
  101.                 End,
  102.             End,
  103.  
  104.             TAG_MORE,msg->ops_AttrList))
  105.     {
  106.         struct data *data = INST_DATA(cl,obj);
  107.  
  108.         data->bar    = bar;
  109.         data->list   = list;
  110.         data->barPos = BARPOS_TOP;
  111.     }
  112.  
  113.     return (ULONG)obj;
  114. }
  115.  
  116. /***********************************************************************/
  117.  
  118. ULONG
  119. mDragQuery(struct IClass *cl,Object *obj,struct MUIP_DragQuery *msg)
  120. {
  121.     struct data *data = INST_DATA(cl,obj);
  122.  
  123.     return (ULONG)((msg->obj==data->bar) ? MUIV_DragQuery_Accept : MUIV_DragQuery_Refuse);
  124. }
  125.  
  126. /***********************************************************************/
  127.  
  128. ULONG
  129. mDragBegin(struct IClass *cl,Object *obj,struct MUIP_DragBegin *msg)
  130. {
  131.     return 0;
  132. }
  133.  
  134. /***********************************************************************/
  135.  
  136. ULONG
  137. findPos(Object *obj,ULONG obPos,ULONG mx,ULONG my)
  138. {
  139.     ULONG bPos;
  140.     LONG  l, t, r, b, w, h;
  141.  
  142.     l = _mleft(obj);
  143.     t = _mtop(obj);
  144.     r = _mright(obj);
  145.     b = _mbottom(obj);
  146.     w = _mwidth(obj)/DD_FACT;
  147.     h = _mheight(obj)/DD_FACT;
  148.  
  149.     bPos = 0;
  150.  
  151.     switch (obPos)
  152.     {
  153.         case BARPOS_LEFT:
  154.             if (mx<l+w) bPos = BARPOS_LEFT;
  155.             else if (mx>r-w) bPos = BARPOS_RIGHT;
  156.                  else if (my<t+h) bPos = BARPOS_TOP;
  157.                       else if (my>b-h) bPos = BARPOS_BOTTOM;
  158.             break;
  159.  
  160.         case BARPOS_RIGHT:
  161.             if (mx>r-w) bPos = BARPOS_RIGHT;
  162.             else if (mx<l+w) bPos = BARPOS_LEFT;
  163.                  else if (my<t+h) bPos = BARPOS_TOP;
  164.                       else if (my>b-h) bPos = BARPOS_BOTTOM;
  165.             break;
  166.  
  167.         case BARPOS_TOP:
  168.             if (my<t+h) bPos = BARPOS_TOP;
  169.             else if (mx<l+w) bPos = BARPOS_LEFT;
  170.                  else if (mx>r-w) bPos = BARPOS_RIGHT;
  171.                       else if (my>b-h) bPos = BARPOS_BOTTOM;
  172.             break;
  173.  
  174.         case BARPOS_BOTTOM:
  175.             if (my>b-h) bPos = BARPOS_BOTTOM;
  176.             else if (mx<l+w) bPos = BARPOS_LEFT;
  177.                  else if (mx>r-w) bPos = BARPOS_RIGHT;
  178.                       else if (my<t+h) bPos = BARPOS_TOP;
  179.             break;
  180.     }
  181.  
  182.     return (bPos==obPos) ? 0 : bPos;
  183. }
  184.  
  185. ULONG
  186. mDragReport(struct IClass *cl,Object *obj,struct MUIP_DragReport *msg)
  187. {
  188.     struct data *data = INST_DATA(cl,obj);
  189.     ULONG       bPos, obPos, horiz, ohoriz, first, ofirst;
  190.  
  191.     if (!msg->update) return MUIV_DragReport_Refresh;
  192.  
  193.     obPos = data->barPos;
  194.     bPos  = findPos(obj,obPos,msg->x,msg->y);
  195.  
  196.     if (bPos==0) return MUIV_DragReport_Continue;
  197.  
  198.     horiz  = (bPos==BARPOS_LEFT)  || (bPos==BARPOS_RIGHT);
  199.     ohoriz = (obPos==BARPOS_LEFT) || (obPos==BARPOS_RIGHT);
  200.  
  201.     first  = (bPos==BARPOS_TOP)  || (bPos==BARPOS_LEFT);
  202.     ofirst = (obPos==BARPOS_TOP) || (obPos==BARPOS_LEFT);
  203.  
  204.     set(data->bar,MUIA_TheBar_Limbo,TRUE);
  205.  
  206.     DoSuperMethod(cl,obj,MUIM_Group_InitChange);
  207.  
  208.     if (first!=ofirst)
  209.     {
  210.         if (first) DoSuperMethod(cl,obj,MUIM_Group_Sort,data->bar,data->list,NULL);
  211.         else DoSuperMethod(cl,obj,MUIM_Group_Sort,data->list,data->bar,NULL);
  212.     }
  213.  
  214.     if (horiz!=ohoriz)
  215.     {
  216.         SetSuperAttrs(cl,obj,MUIA_Group_Horiz,horiz,TAG_DONE);
  217.         set(data->bar,MUIA_Group_Horiz,!horiz);
  218.     }
  219.  
  220.     DoSuperMethod(cl,obj,MUIM_Group_ExitChange);
  221.  
  222.     set(data->bar,MUIA_TheBar_Limbo,FALSE);
  223.  
  224.     data->barPos = bPos;
  225.  
  226.     return MUIV_DragReport_Continue;
  227. }
  228.  
  229. /***********************************************************************/
  230.  
  231. ULONG
  232. mDragFinish(struct IClass *cl,Object *obj,struct MUIP_DragFinish *msg)
  233. {
  234.     return 0;
  235. }
  236.  
  237. /***********************************************************************/
  238.  
  239. ULONG
  240. mDragDrop(struct IClass *cl,Object *obj,struct MUIP_DragDrop *msg)
  241. {
  242.     return 0;
  243. }
  244.  
  245. /***********************************************************************/
  246.  
  247. ULONG SAVEDS ASM
  248. dispatcher(REG(a0) struct IClass *cl,REG(a2) Object *obj,REG(a1) Msg msg)
  249. {
  250.     switch(msg->MethodID)
  251.     {
  252.         case OM_NEW:          return mNew(cl,obj,(APTR)msg);
  253.         case MUIM_DragQuery:  return mDragQuery(cl,obj,(APTR)msg);
  254.         case MUIM_DragBegin:  return mDragBegin(cl,obj,(APTR)msg);
  255.         case MUIM_DragReport: return mDragReport(cl,obj,(APTR)msg);
  256.         case MUIM_DragFinish: return mDragFinish(cl,obj,(APTR)msg);
  257.         case MUIM_DragDrop:   return mDragDrop(cl,obj,(APTR)msg);
  258.         default:              return DoSuperMethodA(cl,obj,msg);
  259.     }
  260. }
  261.  
  262. /***********************************************************************/
  263.  
  264. int
  265. main(int argc,char **argv)
  266. {
  267.     int res;
  268.  
  269.     if (MUIMasterBase = OpenLibrary("muimaster.library",19))
  270.     {
  271.         struct MUI_CustomClass *mainGroupClass;
  272.  
  273.         if (mainGroupClass = MUI_CreateCustomClass(NULL,MUIC_Group,NULL,sizeof(struct data),dispatcher))
  274.         {
  275.             Object *app, *win;
  276.  
  277.             if (app = ApplicationObject,
  278.                     MUIA_Application_Title,         "TheBar Demo7",
  279.                     MUIA_Application_Version,       "$VER: TheBarDemo7 1.0 (24.6.2003)",
  280.                     MUIA_Application_Copyright,     "Copyright 2003 by Alfonso Ranieri",
  281.                     MUIA_Application_Author,        "Alfonso Ranieri <alforan@tin.it>",
  282.                     MUIA_Application_Description,  "TheBar example",
  283.                     MUIA_Application_Base,         "THEBAREXAMPLE",
  284.  
  285.                     SubWindow, win = WindowObject,
  286.                         MUIA_Window_ID,             MAKE_ID('M','A','I','N'),
  287.                         MUIA_Window_Title,          "TheBar Demo7",
  288.                         WindowContents, VGroup,
  289.                             Child, mainGroupObject, End,
  290.                         End,
  291.                     End,
  292.                 End)
  293.             {
  294.                 ULONG sigs = 0;
  295.  
  296.                 DoMethod(win,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,MUIV_Notify_Application,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  297.  
  298.                 set(win,MUIA_Window_Open,TRUE);
  299.  
  300.                 while (DoMethod(app,MUIM_Application_NewInput,&sigs)!=MUIV_Application_ReturnID_Quit)
  301.                 {
  302.                     if (sigs)
  303.                     {
  304.                         sigs = Wait(sigs | SIGBREAKF_CTRL_C);
  305.                         if (sigs & SIGBREAKF_CTRL_C) break;
  306.                     }
  307.                 }
  308.  
  309.                 MUI_DisposeObject(app);
  310.  
  311.                 res = RETURN_OK;
  312.             }
  313.             else
  314.             {
  315.                 printf("%s: can't create application\n",argv[0]);
  316.                 res = RETURN_FAIL;
  317.             }
  318.  
  319.             MUI_DeleteCustomClass(mainGroupClass);
  320.         }
  321.         else
  322.         {
  323.             printf("%s: can't create custom class\n",argv[0]);
  324.             res = RETURN_FAIL;
  325.         }
  326.  
  327.         CloseLibrary(MUIMasterBase);
  328.     }
  329.     else
  330.     {
  331.         printf("%s: Can't open muimaster.library ver 19 or higher\n",argv[0]);
  332.         res = RETURN_ERROR;
  333.     }
  334.  
  335.     return res;
  336. }
  337.  
  338. /***********************************************************************/
  339.